package com.rtx.express.job;

import java.util.Arrays;
import java.util.List;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.rtx.api.annotation.RtxJobAnnotation;
import com.rtx.api.quartz.job.BaseJob;
import com.rtx.edi.model.api.bo.ApiMappingInfoBo;
import com.rtx.edi.platform.baseinfo.service.PlApiService;
import com.rtx.express.handle.ConfigExpress;

@Component
@DisallowConcurrentExecution
@RtxJobAnnotation(  needMappingCode = true,
					jobName = "ZTKYExpressJob",
					description = "中通快运调度任务",
					cron = "0/10 * * * * ?"
					)
public class ZTKYExpressJob implements BaseJob {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private ConfigExpress configExpress;
	
	@Autowired
	PlApiService plApiService;

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		JobDataMap dataMap = context.getJobDetail().getJobDataMap();
		
		String mappingCode = dataMap.get("apiMappingCode")+"";
		
		ApiMappingInfoBo bo = plApiService.getApiMappingInfo(mappingCode);
		
		List<String> whseList = Arrays.asList(bo.getExpressconfig().getWmwhseid().split(","));
		
		for(String whseid:whseList) {
			configExpress.handleExpressSchedul(whseid,bo);
		}
		
	}

}
